<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 系统设置ajax类
 * @package  ajax
 * @subpackage  backend
 * @author   create by allen.qiang
 */

quanli_require('module/base/system/sysConfig.class.php');

class ajax_config {

	public function execute(){

        if (isset($_REQUEST['operFlg']) && is_numeric($_REQUEST['operFlg'])) {

            switch ($_REQUEST['operFlg']) {

                case 1://基础设置
                    $this->editConfig();
                    break;

                default:
                    returnJsonData('参数错误');
                    break;

            }

        } else {
            returnJsonData('参数错误');
        }


	}

    private function editConfig() {

        global $G_PGLOB;

        //实例系统配置类
        $sysConfig = new sysConfig( $G_PGLOB->DBCA );

        if (!isset($_REQUEST['group_id']) || !is_numeric($_REQUEST['group_id'])) {
            returnJsonData('参数错误');
        }
        if (!isset($_REQUEST['params']) || !is_array($_REQUEST['params'])) {
            returnJsonData('参数错误');
        }

        //检查配置组信息
        $group_array = $sysConfig->getGroup( $_REQUEST['group_id'] );
        if (!$group_array) {
            returnJsonData('配置组信息没有找到', 404);
        }

        //更新配置文件
        foreach($_REQUEST['params'] as $k => &$v) {
            $result_array = $sysConfig->updateConfig($k, $v, $_REQUEST['group_id']);
            if ($result_array['code'] != 200) {
                break;
            }
        }
        if ($result_array['code'] != 200) {
            returnJsonData($result_array['message'], $result_array['code']);
        }

        $bool = $sysConfig->editConfigFile( $_REQUEST['group_id'], $group_array['config_group_file'] );
        if ($bool) {
            returnJsonData('配置保存成功', 200);
        } else {
            returnJsonData('配置保存失败', 404);
        }

    }

}